package com.czjtxy.extraTerm.controller.employeemodule;

import com.czjtxy.extraTerm.entity.DO.Temployee;
import com.czjtxy.extraTerm.server.EmployeeService;
import com.czjtxy.extraTerm.serverImpl.EmployeeServiceImpl;
import com.czjtxy.extraTerm.util.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/02 21:07
 */
@WebServlet(name = "UpdateEmployeeServlet", value = "/UpdateEmployeeServlet")
public class UpdateEmployeeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Temployee temployee = new Temployee();
        temployee.setId(Util.stringToInt(req.getParameter("id")));
        temployee.setName(req.getParameter("name"));
        temployee.setCardId(req.getParameter("cardId"));
        temployee.setSex(Util.stringToInt(req.getParameter("sex")));
        temployee.setJobId(Util.stringToInt(req.getParameter("job_id")));
        temployee.setEducation(req.getParameter("education"));
        temployee.setEmail(req.getParameter("email"));
        temployee.setPhone(req.getParameter("phone"));
        temployee.setTel(req.getParameter("tel"));
        temployee.setParty(req.getParameter("party"));
        temployee.setQqNum(req.getParameter("qqNum"));
        temployee.setAddress(req.getParameter("address"));
        temployee.setPostCode(req.getParameter("postCode"));
        temployee.setBirthday(Util.stringToDate(req.getParameter("birthday")));
        temployee.setRace(req.getParameter("race"));
        temployee.setSpeciality(req.getParameter("speciality"));
        temployee.setHobby(req.getParameter("hobby"));
        temployee.setRemark(req.getParameter("ramark"));
        temployee.setDeptId(Util.stringToInt(req.getParameter("dept_id")));

        EmployeeService employeeService = new EmployeeServiceImpl();
        try {
            employeeService.updateEmployee(temployee);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("/EmployeeServlet").forward(req, resp);
    }
}
